<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>列表渲染</title>
    <style>
    .divider {
        background-color: red;
    }
    </style>
</head>

<body>
    <div id="app">
        <h1>1.基本用法</h1>
        <p>语法：v-for="item in items"</p>
        <p>items 是源数据数组，item是数组元素迭代的别名</p>
        <ul>
            <li v-for="item in items">
                {{item.message}}
            </li>
        </ul>
        <p>语法： v-for="(item,index) of items"</p>
        <p>items 是源数据数组，item是数组元素迭代的别名，index是元素索引</p>
        <ul>
            <li v-for="(item,index) in items">
                {{parentMessage}} - {{index}} - {{item.message}}
            </li>
        </ul>
        <p>提示：关键字 in 也可以用 of 代替</p>
        <hr style="width: 100%;height: 2px;border: none;border-top: 2px dashed #000;">
        <h1>2.Template v-for</h1>
        <p>用带有 v-for 的标签来渲染多个元素块</p>
        <ul>
            <template v-for="item in items">
                <li>{{ item.message }}</li>
                <li class="divider"></li>
            </template>
        </ul>
        <hr style="width: 100%;height: 2px;border: none;border-top: 2px dashed #000;">
        <h1>3.对象迭代 v-for</h1>
        <p>迭代出对象键值对的所有值</p>
        <ul>
            <li v-for="value in object">
                {{value}}
            </li>
        </ul>
        <p>加入第二个参数为键值对的key</p>
        <div v-for="(value, key) in object">
            {{ key }} : {{ value }}
        </div>
        <p>加入第三个参数为索引</p>
        <div v-for="(value, key, index) in object">
            {{ index }}. {{ key }} : {{ value }}
        </div>
        <hr style="width: 100%;height: 2px;border: none;border-top: 2px dashed #000;">
        <h1>4.整数迭代 v-for</h1>
        <div><span v-for="n in 10">{{ n }}</span></div>
        <hr style="width: 100%;height: 2px;border: none;border-top: 2px dashed #000;">
        <h1>5.组件 和 v-for</h1>
        <a href="todo.html" title="">todoDemo</a>
    </div>
    <script type="text/javascript" src="../lib/vue.js"></script>
    <script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data: {
            parentMessage: 'Parent',
            items: [{
                message: 'HTML5'
            }, {
                message: 'CSS3'
            }, {
                message: 'Vue.js'
            }],
            object: {
                FirstName: 'John',
                LastName: 'Doe',
                Age: 30
            }
        }
    })
    </script>
</body>

</html>
